﻿using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using Texfina.Core.Common;
using Texfina.Core.Web;
using Texfina.Common.Mg;
using Texfina.Core.Data;
using Texfina.Entity.Pd;
using Texfina.Entity.Mg;
using PDBOQry = Texfina.BOQry.Pd;
using MGBOQry = Texfina.BOQry.Mg;

namespace PD
{
    public partial class wfMaquinaBnd : SearchPage
   {
      public const int _GRDLIST_STPROCESO = 9;
      public const int _GRDLIST_STANULADO = 11;

      protected void Page_Load(object sender, EventArgs e)
      {

         this.LoadInitialSettings();
         if (this.IsPostBack)
         {
            this.LoadInPostBack();
            return;
         }

         this.LoadData();

      }

      public override void LoadInitialSettings()
      {
         Label lbl = (Label)this.Master.FindControl("lblTitle");
         lbl.Text = "Maquinas Producción";
         this.Page.Form.DefaultButton = bttSearch.UniqueID;
      }


      public override void SearchData()
      {
         EMaquinas objE = new EMaquinas();

         //objE.IdPeriodo = Session[ConstSessionVar.PERIODO].ToString();
         objE.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();


         if (this.txtidMaquina.Text == "")
            objE.IdMaquina = null;
         else
            objE.IdMaquina = this.txtidMaquina.Text;

         if (this.txtdsMaquina.Text == "")
            objE.DsMaquina = null;
         else
            objE.DsMaquina = this.txtdsMaquina.Text;

         IBOQuery objBO = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(PDBOQry.Maquinas));
         DataTable dt = objBO.GetByCriteria(objE);

         this.GridSetDataBinding(grdList, dt);

      }

      protected void mnuToolbar_MenuItemClick(Object sender, MenuEventArgs e)
      {
         String strQS = "";

         switch (e.Item.Value)
         {
            case ConstMenuToolbarValue.BUTTON_NEW:
               strQS = "wfMaquinaMnt.aspx?formEA=" + Convert.ToInt32(FormEditAction.AddNew).ToString() + "&IdMaquina=";
               break;
         }
         Response.Redirect(strQS);
      }

      protected void grdList_RowCommand(Object sender, GridViewCommandEventArgs e)
      {
         DataRow dr = this.GridGetRowFromDataKey(grdList, Convert.ToInt32(e.CommandArgument));
         FormEditAction formEA = FormEditAction.AddNew;

         switch (e.CommandName)
         {
            case ConstGridRowCommand.GRIDEDIT:
               formEA = FormEditAction.Edit;
               break;
            case ConstGridRowCommand.GRIDDELETE:
               formEA = FormEditAction.Delete;
               break;
            case ConstGridRowCommand.GRIDPREVIEW:
               //this.PrintReport(Convert.ToInt32(e.CommandArgument));
               return;
         }
         String strQS = "wfMaquinaMnt.aspx?formEA=" + Convert.ToInt32(formEA).ToString()
             + "&IdMaquina=" + dr["idMaquina"].ToString();
             //+ "&IdPlanilla=" + dr["idPlanilla"].ToString() + "&NuProcAnual=" + dr["nuProcAnual"].ToString();
         Response.Redirect(strQS);

      }

      protected void grdList_RowDataBound(Object sender, GridViewRowEventArgs e)
      {
         if (e.Row.RowType == DataControlRowType.DataRow)
         {

            String strRI = e.Row.RowIndex.ToString();

            ImageButton bttedit = (ImageButton)e.Row.FindControl("grdBtt" + ConstGridRowCommand.GRIDEDIT);
            ImageButton bttdelete = (ImageButton)e.Row.FindControl("grdBtt" + ConstGridRowCommand.GRIDDELETE);

            bttedit.OnClientClick = "javascript:return validateGridCommands('" + ConstGridRowCommand.GRIDEDIT + "','" + strRI + "');";
            bttdelete.OnClientClick = "javascript:return validateGridCommands('" + ConstGridRowCommand.GRIDDELETE + "','" + strRI + "');";


            //if (e.Row.Cells[_GRDLIST_STANULADO].Text == ConstFlagEstado.ACTIVADO)
            //{
            //   e.Row.ForeColor = System.Drawing.Color.Red;
            //   bttedit.ImageUrl = "../Images/Icons/Disabled/Edit.png";
            //   bttdelete.ImageUrl = "../Images/Icons/Disabled/Delete.png";
            //}
            //else
            //{
            //   if (e.Row.Cells[_GRDLIST_STPROCESO].Text == ConstEstadoProcePlani.CERRADA)
            //   {
            //      e.Row.ForeColor = System.Drawing.Color.Blue;
            //      bttedit.ImageUrl = "../Images/Icons/Disabled/Edit.png";
            //      bttdelete.ImageUrl = "../Images/Icons/Disabled/Delete.png";
            //   }
            //}


         }

      }

      protected void bttOk_Click(object sender, EventArgs e)
      {
         this.SearchData();
      }
   }
}